import type {
  InterviewQuestionCategory,
  InterviewQuestionCategoryForm,
  InterviewQuestionCategoryQuery,
} from './model';

import type { ID, IDS, PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

enum Api {
  CATEGORY_ADD = '/interview/category/add',
  CATEGORY_CHANGE_STATUS = '/interview/category/changeStatus',
  CATEGORY_DELETE = '/interview/category/delete',
  CATEGORY_EXPORT = '/interview/category/export',
  CATEGORY_GET_BY_AI = '/interview/category/getCategoryByAi', // AI获取分类
  CATEGORY_INFO = '/interview/category/info',
  CATEGORY_LIST = '/interview/category/list',
  CATEGORY_LIST_WITH_COUNT = '/interview/category/listWithCount', // 新增带面试题数量的分类列表接口
  CATEGORY_UPDATE = '/interview/category/update',
  CATEGORY_UPDATE_ORDER = '/interview/category/updateOrder', // 添加排序更新接口
}

// 查询面试题分类列表
export function getCategoryList(params: InterviewQuestionCategoryQuery) {
  return requestClient.get<PageResult<InterviewQuestionCategory>>(
    Api.CATEGORY_LIST,
    {
      params,
    },
  );
}

// 查询面试题分类列表（包含面试题数量）
export function getCategoryListWithCount(
  params: InterviewQuestionCategoryQuery,
) {
  return requestClient.get<
    PageResult<InterviewQuestionCategory & { interviewCount: number }>
  >(Api.CATEGORY_LIST_WITH_COUNT, {
    params,
  });
}

// 查询面试题分类详细信息
export function getCategoryInfo(categoryId: ID) {
  return requestClient.get<InterviewQuestionCategory>(
    `${Api.CATEGORY_INFO}${categoryId}`,
  );
}

// 新增面试题分类
export function addCategory(data: InterviewQuestionCategoryForm) {
  return requestClient.post(Api.CATEGORY_ADD, data);
}

// 修改面试题分类
export function updateCategory(data: InterviewQuestionCategoryForm) {
  return requestClient.put(Api.CATEGORY_UPDATE, data);
}

// 删除面试题分类
export function delCategory(categoryId: IDS) {
  return requestClient.delete(`${Api.CATEGORY_DELETE}${categoryId}`);
}

// 导出面试题分类
export function exportCategory(params: InterviewQuestionCategoryQuery) {
  return commonExport(Api.CATEGORY_EXPORT, params);
}

// 修改面试题分类状态
export function changeCategoryStatus(categoryId: ID, status: string) {
  return requestClient.put(Api.CATEGORY_CHANGE_STATUS, {
    categoryId,
    status,
  });
}

// 更新分类排序
export function updateCategoryOrder(
  data: { categoryId: number; orderNum: number }[],
) {
  return requestClient.put(Api.CATEGORY_UPDATE_ORDER, data);
}

// 通过AI获取分类建议
export function getCategoryByAi(data: { parentId?: number; prompt: string }) {
  return requestClient.post<{ code: number; data: string[]; msg: string }>(
    '/interview/category/getCategoryByAi',
    data,
  );
}
